<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      th:replace="pages/common/main :: layout(~{::title}, ~{::section}, ~{}, ~{::script})">
    <head>
        <title>Dict表单</title>
    </head>
    <body>
        <section>

            <div class="layui-card">
                <div class="layui-card-header">[[${header}]]</div>
                <div class="layui-card-body">
                    <form name="menu" class="layui-form layui-form-pane" lay-filter="FORM">

                        <div class="layui-form-item">
                            <label class="layui-form-label" for="tenant-code">标识符</label>
                            <div class="layui-input-block">
                                <input id="tenant-code" name="code" class="layui-input" lay-verify="required"
                                       th:value="${tenant.getCode()}" th:readonly="${isUpdate}"/>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label" for="tenant-name">名称</label>
                            <div class="layui-input-block">
                                <input id="tenant-name" name="name" class="layui-input" lay-verify="required"
                                       th:value="${tenant.getName()}"/>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label" for="tenant-description">描述</label>
                            <div class="layui-input-block">
                                <textarea id="tenant-description" name="description" class="layui-textarea">[[${tenant.getDescription()}]]</textarea>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">数据源</label>
                            <div class="layui-input-block">
                                <select name="datasource">
                                    <option value="master">默认数据源</option>
                                    <option th:value="${item.key}" th:each="item:${datasourceLabels}"
                                        th:selected="${item.key==tenant.getDatasource()}">[[${item.value}]]</option>
                                </select>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label" for="tenant-username">默认用户</label>
                            <div class="layui-input-block yak-radios">
                                <input id="tenant-username" name="username" class="layui-input" lay-verify="required"
                                       th:value="${tenant.getUsername()}" th:readonly="${isUpdate}"/>
                            </div>
                        </div>


                        <div class="layui-form-item">
                            <label class="layui-form-label" for="tenant-password">默认密码</label>
                            <div class="layui-input-block">
                                <input id="tenant-password" name="password" class="layui-input" lay-verify="required"
                                       th:value="${tenant.getPassword()}" th:readonly="${isUpdate}"/>
                            </div>
                        </div>

                        <div class="layui-form-item" pane="">
                            <label class="layui-form-label">激活</label>
                            <div class="layui-input-block">
                                <input type="radio" name="active" th:each="item:${activeLabels}"
                                       th:value="${item.key}" th:title="${item.value}"
                                       th:checked="${item.key==tenant.getActive()}"
                                >
                            </div>
                        </div>


                        <div class="layui-form-item layui-input-block">
                            <button type="submit" class="layui-btn" lay-submit lay-filter="form-submit">立即提交</button>
                        </div>

                    </form>
                </div>
            </div>

        </section>
        <script th:inline="javascript">
            layui.use(['element', 'form', 'jquery', 'ax', 'admin'], function () {
                var form = layui.form,
                    $ax = layui.ax;

                form.on('submit(form-submit)', function (data) {
                    var ajax = new $ax(Kong.ctxPath + "/sys/tenant/save", function (data) {
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index)
                        top.layui.admin.refresh()
                    });
                    // console.log(data)
                    // ajax.setHeadersValue("Model-Class", "");
                    ajax.setMethod("post");
                    ajax.setData(data.field);
                    ajax.send();
                    return false;
                })

            });

        </script>
    </body>
</html>